const rp = require("request-promise");
const fs = require("fs");
const path = require("path");
const utli = require("util");
const unlink = utli.promisify(fs.unlink);
const { uploadFile } = require('tools-factory-tang');
const addImgs = async req => {
    const { data: { _id, url } } = await uploadFile(req);
    var options = {
        method: 'PATCH',
        uri: `http://localhost:3001/cinemas/${_id}/imgs/${encodeURIComponent(url)}`,
        json: true // Automatically stringifies the body to JSON
    };
    return await rp(options);
};
const deleteimg = async url => {
    const imgUrl = path.join(path.resolve(__dirname, "../public"), url);
    try{
        await unlink(imgUrl);
    }catch(error){
        console.log(error);
        return{
            status:false
        }
    }
}
module.exports = { addImgs, deleteimg }
